package com.example.demo.controller;

import com.example.demo.service.DeepSeekService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.Map;

@RestController
@RequestMapping("/chat")
public class ChatController {

    private final DeepSeekService deepSeekService;

    // 构造函数注入，确保 deepSeekService 在类实例化时被正确初始化
    public ChatController(DeepSeekService deepSeekService) {
        this.deepSeekService = deepSeekService;
    }

    @PostMapping
    public ResponseEntity<?> chat(@RequestBody Map<String, String> request) {
        String response = deepSeekService.chat(request.get("message"));
        return ResponseEntity.ok(Collections.singletonMap("response", response));
    }
}
